package org.hs.phd.odi.tracking.tool.bgsub.fgdetection;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.UnsupportedLookAndFeelException;

import org.hs.phd.common.simpleplayer.FramePlayer;
import org.hs.phd.odi.bgsub.FGObjectDetectionFilter;
import org.hs.phd.odi.tracking.inputscenarios.Scenario20111123Dia6Exp512;
import org.hs.phd.odi.tracking.layers.FrameNoOverlayLayer;


public class FGObjectDetectionMain {

    public static void main(String[] args) throws Exception{
        setNimbusLAFIfAvailable();

        Scenario20111123Dia6Exp512 scenario = new Scenario20111123Dia6Exp512(3966);
        final FramePlayer player = scenario.getPlayer();

         
      
        //player.addFilter(new DownSampleFilter());
		player.addFilter(new FGObjectDetectionFilter(scenario.getTransformation()));
		
		player.addViewerLayer(new FrameNoOverlayLayer());
                        
        final FGObjectDetectionFrame view = new FGObjectDetectionFrame(player);
        view.addWindowListener(new WindowAdapter() {
		
        	@Override
        	public void windowOpened(WindowEvent e) {
        		//player.stepNext();
        		player.play();
        	}
		
        	@Override
        	public void windowClosing(WindowEvent e) {
        		player.stop();
        		view.dispose();
        		System.exit(0);
        	}
        });
        
        view.pack();
        view.setVisible(true);
    }
    
	private static void setNimbusLAFIfAvailable()
			throws ClassNotFoundException, InstantiationException,
			IllegalAccessException, UnsupportedLookAndFeelException {
		javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels = javax.swing.UIManager.getInstalledLookAndFeels();
        for (int idx = 0; idx < installedLookAndFeels.length; idx++) {
            if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
                javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
                break;
            }
        }
	}
}
